package com.zcf.gameController.gameUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 三公
 * @author jj
 * @date 2019/11/16 11:05
 */
public class SgHandPattern {
    public final static int[] tbrands = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
//-------------------------特殊牌型--------------------------------------------------------

    /**
    * @description : 运算结果
    * @param cards
    * @date : 2019/11/20 13:41
    * @author : jj
    */
    public int  algorithm(List<Integer> cards){
        int a = tbrands[cards.get(0)%13];
        int b = tbrands[cards.get(1)%13];
        int c = tbrands[cards.get(2)%13];
        int s1 = sanGong(a, b, c);
        if (s1!=0){
            return s1;
        }
        int s2 = sanTiao(a, b, c);
        if (s2!=0){
            return s2;
        }
        int s3 = hunSanGong(a, b, c,cards);
        if (s3!=0){
            return s3;
        }
        int s4 = dianZi(a, b, c,cards);
        if (s4!=0){
            return s4;
        }
        int s5 = zeros(a, b, c,cards);
        return s5 !=0 ? s5 : 0;
    }
    /**
    * @description :判断是否是三公
    * @date : 2019/11/20 13:49
    * @author : jj
    */
    private int sanGong(int a,int b,int c ){
        if (a==3) {
            if (a == b && a == c) {
                return 1;
            }
        }
        return 0;
    }
    /**
     * @description :判断是否是三条
     * @date : 2019/11/20 13:49
     * @author : jj
     */
    private int sanTiao(int a,int b,int c ){
        int number=1;
        for (int i = 13 ; i > 0;i--){
            number++;
            if (a == b && a == c && a == i) {
                if (number>2){
                    number--;
                }
                return number;
            }
        }
        return 0;
    }
    /**
     * @description :判断是否是混三公
     * @date : 2019/11/20 13:49
     * @author : jj
     */
    private int hunSanGong(int a,int b,int c,List<Integer> cards ){
        if (a>10&&b>10&&c>10){
            int max = getMax(cards);
            int number =13;
            for (int i = 13; i >10;i--){
                for (int j=0;j<4;j++){
                    number++;
                    if (max/13==j&&tbrands[max%13]==i){
                        return number;
                    }
                }
            }
        }
        return 0;
    }
    /**
     * @description :点子数
     * @date : 2019/11/20 15:03
     * @author : jj
     */
    private int dianZi(int a,int b,int c,List<Integer> cards){
        int a1 = cards.get(0)%13;
        int b1 = cards.get(1)%13;
        int c1 = cards.get(2)%13;
        if (a>10){
            a=10;
        }
        if (b>10){
            b=10;
        }
        if (c>10){
            c=10;
        }
        int sum = (a + b + c)%10;
        int max = getMax(cards);
        int number=25;
        if (sum==0){
            return 0;
        }
        int gz=0;
        if (a1>10&&b1>10||a1>10&&c1>10||b1>10&&c1>10){
            gz=2;
        }else if (a1 > 10 || b1 > 10 || c1 > 10 ){
            gz = 1;
        }
        for (int i =9; i > 0; i--) {
            for (int n = 2; n >= 0 ; n--) {
                for (int j = 13; j > 0; j--) {
                    for (int k = 0; k < 4; k++) {
                        number++;
                        if (sum == i && tbrands[max % 13] == j && max / 13 == k &&gz==n) {
                            return number;
                        }
                    }
                }
            }
        }

        return 0;
    }
    /**
     * @description :判断是否为0
     * @date : 2019/11/20 13:49
     * @author : jj
     */
    private int zeros(int a,int b,int c,List<Integer> cards ){
        if (a>10){
            a=10;
        }
        if (b>10){
            b=10;
        }
        if (c>10){
            c=10;
        }
        int sum=(a+b+c)%10;
        if (sum!=0){
            return 0;
        }
        int max = getMax(cards);
        int number=2000;

        for (int i =9; i > 0; i--) {
            for (int j = 13; j > 0; j--){
                for (int k =0 ; k < 4; k++) {
                    number++;
                    if (tbrands[max%13]==j&&max/13==k){
                        return number;
                    }
                }
            }
        }
        return 0;
    }
    /**
     * @description :判断三张牌中最大的
     * @param cards
     * @date : 2019/11/20 14:19
     * @author : jj
     */
    private int  getMax(List<Integer> cards) {
        int a = cards.get(0);
        int b = cards.get(1);
        int c = cards.get(2);
        if (a%13 > b%13) {
            if (a%13 > c%13) {
                return a;
            } else if (a%13 == c%13){
                return a > c ? a : c;
            }else {
                return c;
            }
        } else if (a%13 == b%13){
            if (a>b){
                if (a%13 > c%13) {
                    return a;
                } else if (a%13 == c%13){
                    return a > c ? a : c;
                }else {
                    return c;
                }
            }else {
                if (b%13 > c%13) {
                    return b;
                } else if (b%13 == c%13){
                    return b > c ? b : c;
                }else {
                    return c;
                }
            }
        }else {
            if (b%13 > c%13) {
                return b;
            } else if (b%13 == c%13){
                return b > c ? b : c;
            }else {
                return c;
            }
        }
    }
    public static void main(String[] args) {
        Random rand = new Random();
        for (int i = 0; i < 2; i++){
            List<Integer> cards=new ArrayList<>();
          /*  int i1 = rand.nextInt(13);
            int i2 = rand.nextInt(35);
            int i3 = rand.nextInt(26);*/
            cards.add(46);
            cards.add(14);
            cards.add(24);
            System.out.println(cards.get(0));
            System.out.println(tbrands[cards.get(0)%13]);
            SgHandPattern ps=new SgHandPattern();
            int algorithm = ps.algorithm(cards);
            System.out.println(algorithm);
        }


    }
}
